home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////
- // Harrow Software 1996
- // Example game script
- // Main script
- //
-
- // This is an example of a sprite based game
- // The object is to shoot the never ending supply of colored balls
- // Notice that handles are freed after they are used
-
- clear window color 100,100,100
-
- start_game:
-
- // hide the mouse and set the position
- // of the cursor to the centre of the screen
- //
- break mode OFF
- mouse mode OFF
- x_mid = GRAPHICS_WINDOW_XMAX/2
- y_mid = GRAPHICS_WINDOW_YMAX/2
- mouse position x_mid,y_mid
-
- // load all resources
- //
- call load_all_bitmaps
- call load_sounds
-
- // prepare the good guy
- //
- good_guy_script = new script "game_2.sxt"
- good_guy_script call initialize: @good_guy_bitmaps
- good_guy_script call set_position: x_mid,y_mid
-
- // make lists for the colored balls and release 6 balls
- //
- colored_ball_scripts = new list
- colored_ball_sprites = new list
- for n = 1 to 6
- call new_colored_ball
-
- // make lists for the cannon shots
- //
- cannon_shot_scripts = new list
- cannon_shot_sprites = new list
-
- // start timing events
- //
- update_sprite_time = TIMER
-
- // detect messages from mouse and keyboard
- //
- win_msg = 0
- while win_msg != WM_KEYDOWN && win_msg != WM_RBUTTONDOWN
- peek message win_msg, wpm, x_parm, y_parm
- switch win_msg
-
- case WM_LBUTTONDOWN
- play sound shooting_sound
- call shoot_cannon
-
- case WM_MOUSEMOVE
- x_off = x_parm - x_mid // offset of mouse
- y_off = y_parm - y_mid
- if x_off || y_off
- //
- // if offset then move good guy
- //
- good_guy_script call offset_position: x_off,y_off
- mouse position x_mid,y_mid // centre mouse again
-
- // update sprites 15 times per second
- //
- if TIMER > update_sprite_time + 7
- update_sprite_time = TIMER
-
- // update the good guy
- //
- good_guy_script call update_sprite
-
- // update the cannon shots
- // count down the list in case any shots get removed
- //
- cannon_shot_script = cannon_shot_scripts loop n mode LIST_DOWN
- state = cannon_shot_script call update_sprite
- if state == FALSE
- // find the position and remove the shot
- //
- pos = cannon_shot_scripts find @cannon_shot_script
- cannon_shot_scripts remove pos // remove shot
- cannon_shot_sprites remove pos
-
- // detect for collision with colored ball
- //
- cannon_shot_sprite = @cannon_shot_script.my_sprite
- other_sprite = sprite cannon_shot_sprite collision SPRITE_EXTERNAL loop m
- if $other_sprite.name == "colored ball"
- // get the position of the ball that was hit
- pos = colored_ball_sprites find @other_sprite
- colored_ball_scripts remove pos
- colored_ball_sprites remove pos
- cannon_shot_script call explode
- play sound exploding_sound
- call new_colored_ball
-
- free cannon_shot_sprite // free the handles
- free cannon_shot_script
- free other_sprite
-
- // update the colored balls
- //
- colored_ball_script = colored_ball_scripts loop n
- colored_ball_script call update_sprite
- free colored_ball_script // release the handle
-
- update sprites
-
- free all
- update sprites
- mouse mode ON
- return
-
- ///////////////
- new_colored_ball:
- colored_ball_script = new script "game_3.sxt"
- colored_ball_sprite = new sprite
- colored_ball_script call initialize:\
- @colored_ball_sprite, @colored_ball_bitmaps
- colored_ball_scripts add colored_ball_script
- colored_ball_sprites add colored_ball_sprite
- free colored_ball_script // free the handles
- free colored_ball_sprite
-
- //////////////
- shoot_cannon:
- x,y,u,v = good_guy_script call get_shot_position
- cannon_shot_script = new script "game_4.sxt"
- cannon_shot_sprite = new sprite
- cannon_shot_script call initialize: @cannon_shot_sprite, @cannon_shot_bitmaps, x,y,u,v
- cannon_shot_scripts add cannon_shot_script
- cannon_shot_sprites add cannon_shot_sprite
- free cannon_shot_script
- free cannon_shot_sprite
-
- ////////////////////////////////////////////
- // Load files from disk and prepare them
- //
-
- load_all_bitmaps:
- files = new byte[10][32]
-
- // load the bitmaps for the colored balls
- $files[0] = "ball_red";"ball_grn";"ball_blu";""
- colored_ball_bitmaps = call load_bitmaps: @files
-
- // load the bitmaps for the cannon shot
- $files[0] = "km_shot";"km_exp";"km_dust";""
- cannon_shot_bitmaps = call load_bitmaps: @files
-
- // load the bitmaps for the good guy
- $files[0] = "km_guy";"km_fire1";"km_fire2";""
- good_guy_bitmaps = call load_bitmaps: @files
-
- // put all bitmaps on one list
- all_bitmaps_list = new list
- all_bitmaps_list add colored_ball_bitmaps
- all_bitmaps_list add cannon_shot_bitmaps
- all_bitmaps_list add good_guy_bitmaps
-
- // use a loop list to get a handle to every bitmap
- // allocate palette positions and remap all bitmaps
- // to the system palette
- b = all_bitmaps_list loop n type "Bitmap" mode LIST_TREE
- compose bitmap b
- remap bitmap b
- bitmap b transparency 0,255,0 // set the transparency color
-
- /////////////////////// load bitmaps
- local load_bitmaps: files
- bitmaps = new list // bitmap list
- for n = 0 to 9
- if !(files[n][0]) then break // empty string
- load $files[n], ".gif" bitmap b // load a gif file
- bitmaps add b // add it to the list
- return @bitmaps
-
- ///////////////// load sounds
- load_sounds:
- load "shoot.wav" sound shooting_sound
- load "explode.wav" sound exploding_sound
-
- ///////////////////////////
- /////////////////////